<?php
namespace Home\Controller;
use Think\Controller;

class EventController extends BaseController {
    public static function index($page){
        $data = array(
            'ip' => $_SERVER['HTTP_X_REAL_IP'],
            'time' => date('Y-m-d', time()),
            'page' => $page
        );
        M('log')->add($data);
    }

    public function dataReturn() {
        $get = trim(I('get.date'));
        $data = $this->getData($get);
        header("Access-Control-Allow-Origin: *");
        $this->ajaxReturn($data);
    }

    private function getData($date) {
        $log  = M('log');
        $map0 = array(
            'time' => $date,
            'page' => '首页'
        );
        $index = $log->where($map0)->distinct(ip)->count();
        $map1 = array(
            'time' => $date,
            'page' => '商品浏览页面'
        );
        $goodsview = $log->where($map1)->distinct(ip)->count();
        $map2 = array(
            'time' => $date,
            'page' => '查看了更多商品'
        );
        $moregoods = $log->where($map2)->distinct(ip)->count();
        $map3 = array(
            'time' => $date,
            'page' => '个人展示页面'
        );
        $person = $log->where($map3)->distinct(ip)->count();
        $map4 = array(
            'time' => $date,
            'page' => '专题页面'
        );
        $major = $log->where($map4)->distinct(ip)->count();
        $map5 = array(
            'time' => $date,
            'page' => '搜索页面'
        );
        $search = $log->where($map5)->distinct(ip)->count();
        $map6 = array(
            'time' => $date,
            'page' => '商家排行榜'
        );
        $storelist = $log->where($map6)->distinct(ip)->count();
        $map7 = array(
            'time' => $date,
            'page' => '标签排行榜'
        );
        $taglist = $log->where($map7)->distinct(ip)->count();

        $data = array(
            'index' => $index,
            'goodsview' => $goodsview,
            'moregoods' => $moregoods,
            'person' => $person,
            'major' => $major,
            'search' => $search,
            'storelist' => $storelist,
            'taglist' => $taglist
        );
        return $data;
    }
}